<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('回复电话工单')"/>
    <style>
        label {
            font-weight: bold;
        }

        @font-face {
            font-family: 'huawen';
            src: url("/fonts/huawen.woff2");
        }
    </style>
</head>

<body style="background-color: #F4F6FA;font-size: 13px;font-family:'huawen' ;font-weight: bold">
<iframe id="showWorkForm" width="100%" scrolling="no" th:src="@{'/system/mTelWF/cmnFile/showWorkFormInfo/'+${sendBackEty.wfId}}" frameborder="0" seamless></iframe>
<div class="main-content" style="margin: 0;padding: 0">

    <form id="form-user-add" th:object="${sendBackEty}" class="form-horizontal" style="background-color: #F4F6FA">
        <input type="hidden" th:field="*{wfId}"/>
        <input type="hidden" th:field="*{pkId}"/>
        <input type="hidden" th:field="*{sortCode}"/>
        <input type="hidden" th:field="*{sdeptName}"/>
        <input type="hidden" th:field="*{sdeptId}"/>
        <input type="hidden" id="crtUserRole" th:value="${user.roles.get(0).roleId}"/>
        <input type="hidden" id="setProId" th:value="${workForm.setProId}"/>
        <input type="hidden" name="crtStepId" id="crtStepId"/>
        <input type="hidden" name="crtStepName" id="crtStepName"/>
        <input type="hidden" name="backState" id="backState" th:value="*{backState}"/>
        <input type="hidden" name="opinion" id="opinion">
        <input type="hidden" name="txtReason" id="txtReason">

        <div class="col-sm-12 grid-container" style="display:flex;">
            <div class="col-sm-6 entering-page">
                <!--    回复电话工单    -->
                <div class="col-sm-12 tltieBoder">
                    <div class="blueBorder"></div>
                    <h4 style="margin:0 0 0 10px">回复信息</h4>
                </div>
                <!--    隐藏内容       -->
                <div style="display: none">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">建议办结及理由：</label>
                            <div class="col-sm-6">
                                <textarea th:field="*{reason}" maxlength="1000"
                                          class="form-control"
                                          cols="60"
                                          rows="3"></textarea>
                            </div>
                        </div>

                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd" style="color: red">执行处(科)室：</label>
                            <div class="col-sm-6">
                                <input th:field="*{bdutyDept}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd" style="color: red">联系电话：</label>
                            <div class="col-sm-6">
                                <input th:field="*{bdutyTel}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">回复人：</label>
                            <div class="col-sm-6">
                                <input name="buserName" th:value="${user.userName}" type="text" class="form-control">
                                <input type="hidden" name="buserNo" th:value="${user.userNo}"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">回复时间：</label>
                            <div class="col-sm-6">
                                <input name="backTime" th:value="${nowTime}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">备注：</label>
                            <div class="col-sm-6">
                                <input th:field="*{backRemark}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label entering-pd" style="color: red">回复内容:</br>(供派单部门使用)</label>
                        <div class="col-sm-10">
                            <select name="replyRc" id="replyRc"
                                    th:with="replyRn=${replyTemplate}"
                                    onchange="dropChgSendTextOnly(this,'backDesc');"
                                    class="form-control m-b phoneCategory">
                                <th:block th:each="item,index : ${replyRn}">
                                    <option th:text="${item['replyRn']}" th:value="${item['replyNo']}"></option>
                                </th:block>
                            </select>
                            <textarea id="backDesc" th:field="*{backDesc}" maxlength="3500"
                                      class="form-control opinion"
                                      rows="7" required="required"></textarea>
                        </div>
                    </div>
                </div>
                <!--按钮-->
                <div class="col-sm-12" style="display: flex;justify-content:center;margin:15px 0px 15px 0px">
                    <div class="form-group">
                        <div class="col-sm-3 col-sm-offset-6"  style="display: flex;justify-content: space-evenly;">
                            <button type="button" id="replyAudit" class="btn btn-sm btn-primary" onclick="replyOrAudit()">回复并审核</button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="button" class="btn btn-sm btn-success" onclick="sub()">回复</button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="button" class="btn btn-sm btn-light" onclick="parent.closeItem()">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6" style="padding: 0;">
                <th:block th:each="sons,stat: ${sonBackList}">
                    <div class="col-sm-6 pd2" th:if="${son != null}" th:unless="${#lists.isEmpty(sonBackList)}"  th:each="son,stat: ${sons}">
                        <div class="ibox mbi10">
                            <div class="ibox-title">[[${son.sbdeptName}]]&nbsp;回复审核情况：
                                <span th:switch="${son.backState}">
                                    <span th:case="0" style="color: red">未回复</span>
                                    <span th:case="10" style="color: red">已回(未审)</span>
                                    <span th:case="*" style="color: red">已审</span>
                                </span>
                            </div>
                            <div class="ibox-content">
                                <p>交办次序：[[${son.seqName}]] <a th:unless="${#strings.isEmpty(son.backDesc)}" style="float: right;" class="btn btn-outline btn-primary copyBtn" onclick="copyBackDesc(this);return false;">复制</a></p>
                                <p>办理性质：[[${son.sortName}]]</p>
                                <p>执行处(科)室：[[${son.bdutyDept}]]</p>
                                <p>回复人：[[${son.buserName}]]</p>
                                <p>联系电话：[[${son.bdutyTel}]]</p>
                                <p>回复时间：[[${#dates.format(son.backTime,'yyyy-MM-dd HH:mm:ss')}]]</p>
                                <p><span>回复内容：<span><span class="replyContent">[[${son.backDesc}]]</span></p>
                            </div>
                        </div>
                    </div>
                </th:block>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<script>
    var prefix = ctx + "system/mTelWF";

    // 获取用户部门，展示是否显示回复并审核按钮
    var nowDept = [[${session.ssnObjUser.deptId}]];
    // 锦江区隐藏
    if(nowDept == '304040'){
        $("#replyAudit").attr('style','display:none;');//隐藏
    }else {
        $("#replyAudit").attr('style','display:block;');//显示
    }

    $("#showWorkForm").on("load",function(){//iframe加载完后 高度自适应。
        var showWorkForm = document.getElementById("showWorkForm").contentDocument || document.getElementById("showWorkForm").contentWindow.document,
            frame_height = showWorkForm.documentElement.scrollHeight;
        $("#showWorkForm").height(frame_height);
    });


    function sub() {
        //根据当前登录用户的角色决定由哪个部门审查
        var stepRoles = "210,240,260,290,310,340";
        var crtRole = $("#crtUserRole").val();
        if (stepRoles.indexOf(crtRole) > -1) {
            $("#crtStepId").val("800");
            $("#crtStepName").val("待市级部门审查");
        } else { //三级不驱动流程
            $("#crtStepId").val("400");
            $("#crtStepName").val("待区县部门审查");
        }
        if ($.validate.form()) {
            var backDesc = "reply"+$("#backDesc").val();
            $("#backDesc").val(backDesc);
            let url = prefix + "/cmnFile/dlReplyS";
            let data = $('#form-user-add').serializeArray();
            parent.$.operate.saveTab(url, data);
        }
    }

    //回复并审核
    function replyOrAudit(){
        //根据当前登录用户的角色决定由哪个部门审查
        var stepRoles = "210,240,260,290,310,340";
        var crtRole = $("#crtUserRole").val();
        if (stepRoles.indexOf(crtRole) > -1) {
            $("#crtStepId").val("800");
            $("#crtStepName").val("待市级部门审查");
        } else { //三级不驱动流程
            $("#crtStepId").val("400");
            $("#crtStepName").val("待区县部门审查");
        }
        if ($.validate.form()) {
            let url = prefix + "/cmnFile/dlReplyS";
            let data = $('#form-user-add').serializeArray();
            $.ajax({
                url: url,
                data: data,
                type: 'POST',
                success: function (data) {
                    passOrNot(1);//审核同意
                }
            })
        }
    }

    //审核
    function passOrNot(flag){
        var act = parseInt(flag);
        if(act<1){
            if($("#txtReason").val().length<1){
                $.modal.alertWarning("请输入不通过理由");
                return false;
            }
            $("#opinion").val("不同意");
        }
        else{
            if($("#opinion").val().length<1)
                $("#opinion").val("同意");
        }
        //根据当前登录用户的角色决定由哪个部门审查
        var crtPro = $("#setProId").val();//工单类型
        var sortCode = $('#sortCode').val();
        var crtRole = $("#crtUserRole").val();
        var stepRoles = "210,240,260,290,310,340";
        if(stepRoles.indexOf(crtRole) > -1){//市级
            if ("11" != sortCode) {
                if (act < 1)
                    $('#backState').val(12);
                else
                    $('#backState').val(11);
            }else{
                //主办
                if("11" != crtPro.toString()){
                    if(act<1){
                        $('#backState').val(12);
                        $("#crtStepId").val("801");
                        $("#crtStepName").val("市级不通过");
                    }
                    else{
                        $('#backState').val(11);
                        $("#crtStepId").val("810");
                        $("#crtStepName").val("待效能办审查");
                    }
                }
                else{//11 普通工单
                    if(act<1){
                        $('#backState').val(12);
                        $("#crtStepId").val("801");
                        $("#crtStepName").val("市级不通过");
                    }
                    else{
                        $('#backState').val(11);
                        $("#crtStepId").val("810");
                        $("#crtStepName").val("待审定结果");
                    }
                }
            }
        }
        else{
            if(act<1){
                $("#backState").val(12);
            }
            else{
                $("#backState").val(11);
            }
        }
        if ($.validate.form()) {
            let url = prefix + "/cmnFile/dlChkReply";
            let data = $('#form-user-add').serializeArray();
            parent.$.operate.saveTab(url,data);
        }
    }

    function dropChgSendTextOnly(e,acpId) {
        if (e.options[e.selectedIndex].text==='----请选择回复内容----') return '';
        let showText = $("#replyRc").find("option:selected").text();
        document.getElementById(acpId).value = showText + '\n';
    }
</script>
</body>
</html>

